<?php
/**
* @desc 广告表单处理
* @author kevin.wang
* @date 2015-01-01 12:00:00
**/
class AdverForm extends BaseForm
{
	public $name;
	public $sort;
	public $start_time;
	public $end_time;
	public $image;
	public $is_show;
	public $link_url;
	public $adver_type;
	//表单规则
	public function rules()
	{
		return array(
			array('name, sort, start_time, end_time, image, link_url', 'required', 'message'=>'必填字段不能为空'),
			array('name', 'unique' , 'on'=>'add', 'className'=>'Adver', 'message'=>'广告名称已存在'),
			array('sort', 'numerical', 'message'=>'排序必须为数字'),
			array('is_show', 'boolean', 'message'=>'是否显示为布尔值'),
			array('adver_type', 'in', 'range'=>array(0,1,3,4,5), 'message'=>'类型不在指定范围')
		);
	}
	//写入数据
	public function saveData(){
		$model = new Adver;
		$userInfo = json_decode(Yii::app()->session['userinfo'], true);
		$data = $this->attributes;
		$data['author'] = $userInfo['username'];
		return $model->insertAdver($data);
	}
	//修改数据
	public function editData($id){
		$model = new Adver;
		$userInfo = json_decode(Yii::app()->session['userinfo'], true);
		return $model->editAdver($id, $this->attributes);
	}
}
